const path = require('path')
const UglifyPlugin = require('uglifyjs-webpack-plugin')
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');

module.exports = {
    publicPath:'./',
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    autoprefixer({
                        browsers: ['Android >= 4.0', 'iOS >= 7']
                    }),
                    pxtorem({
                        rootValue: 37.5,
                        propList: ['*'],
                    })
                ]
            }
        }
    },
    chainWebpack: config => {
        
    },
    configureWebpack: (config) => {
        let optimization = {
            runtimeChunk: 'single',
            splitChunks: {
                chunks: 'all',
                maxInitialRequests: Infinity,
                minSize: 20000,
                cacheGroups: {
                    vendor: {
                        test: /[\\/]node_modules[\\/]/,
                        name(module) {
                            // get the name. E.g. node_modules/packageName/not/this/part.js
                            // or node_modules/packageName
                            const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
                            // npm package names are URL-safe, but some servers don't like @ symbols
                            return `npm.${packageName.replace('@', '')}`
                        }
                    }
                }
            },
            minimizer: [new UglifyPlugin({
                uglifyOptions: {
                    compress: {
                        // warnings: false,
                        drop_console: true, // console
                        drop_debugger: false,
                        pure_funcs: ['console.log'] // 移除console
                    }
                }
            })]
        }
        Object.assign(config, {
            optimization
        })
    },
    productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
    parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用，仅作用于生产构建。
};